<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .on1 {
            width: 800px;
            height: 100px;
            margin: auto;
            position: relative;
        }
        .on2 {
            width: 800px;
            height: 500px;
            position: relative;
        }
        .on2 img {
            width: 100%;
            height: 100%;
            position: absolute;
        }
        .l {
            width: 50px;
            height: 100px;
            text-align: center;
            line-height: 100px;
            background-color: rgba(0, 0, 0, .5);
            font-size: 30px;
            color: #fff;
            position: absolute;
            left: 0;
            top: 250px;
            margin-top: -50px;
        }
        .r {
            width: 50px;
            height: 100px;
            text-align: center;
            line-height: 100px;
            background-color: rgba(0, 0, 0, .5);
            font-size: 30px;
            color: #fff;
            position: absolute;
            right: 0;
            top: 250px;
            margin-top: -50px;
        }
        /* on1的动画 */
        .on1-leave {
            left: 0 !important;
            opacity: 1 !important;
            /* left: 500px !important; */
        }
        .on1-leave-active {
            transition: all 1s;
        }
        .on1-leave-to {
            left: 500px !important;
            opacity: 0 !important;
        }
        .on1-enter {
            left: 500 !important;
            opacity: 0 !important;
            /* left: 500px !important; */
        }
        .on1-enter-active {
            transition: all 1s;
        }
        .on1-enter-to {
            left: 0 !important;
            opacity: 1 !important;
        }
        /* on2的动画 */
        .on2-leave {
            left: 0 !important;
            opacity: 1 !important;
            /* left: 500px !important; */
        }
        .on2-leave-active {
            transition: all 1s;
        }
        .on2-leave-to {
            left: -500px !important;
            opacity: 0 !important;
        }
        .on2-enter {
            left: -500 !important;
            opacity: 0 !important;
            /* left: 500px !important; */
        }
        .on2-enter-active {
            transition: all 1s;
        }
        .on2-enter-to {
            left: 0 !important;
            opacity: 1 !important;
        }
    </style>
</head>
<body>
    <div id="box">
        <div class="on1">
            <div class="on2">
                <transition v-for="(i,$index) in arr" :name='type'>
                    <img :src="i" alt="" v-show="$index==index">
                </transition>
            </div>
            <div class="l" @click="l"><</div>
            <div class="r" @click="r">></div>
        </div>
    </div>
</body>
<script src="./vue.js"></script>
<script>
    new Vue({
        el:"#box",
        data:{
            arr:[
                './img/1.jpg',
                './img/2.jpg',
                './img/3.jpg',
                './img/4.jpg',
                './img/5.jpg',
            ],
            index:0,
            type:'on1'
        },
        methods:{
            l(){
                this.type = 'on1'
                this.index--
                if(this.index<=-1){
                    this.index = this.arr.length-1
                }
            },
            r(){
                this.type = 'on2'
                this.index++
                if(this.index>=this.arr.length){
                    this.index = 0
                }
            }
        }
    })
</script>
</html>